﻿//-----------------------------------------------------------------------
// <copyright file="LogController.cs" company="SLWY Enterprises">
// * Copyright (C) 2017 四川商旅无忧科技有限公司 版权所有。
// * version : 1.0
// * author  : qinchaoyue
// * FileName: LogController.cs
// * history : created by qinchaoyue 2017-11-21 01:36:51
// </copyright>
//-----------------------------------------------------------------------

namespace WebApplication.Controllers
{
    using System;

    using Microsoft.AspNetCore.Mvc;

    using Slwy.Logger.Contracts;
    using Slwy.Mvc.Controller;

    /// <summary>
    /// Log 测试类
    /// </summary>
    [Route("api/test/log")]
    public class LogController : SlwyController
    {
        /// <summary>
        /// 日志操作器
        /// </summary>
        private readonly ILogger _logger;

        /// <summary>
        /// Initializes a new instance of the <see cref="LogController"/> class. 
        /// 获取日志操作器
        /// </summary>
        /// <param name="logger"> 日志操作器
        /// </param>
        public LogController(ILogger logger)
        {
            this._logger = logger;
        }

        /// <summary>
        /// 测试 写入 Information 日志
        /// </summary>
        /// <returns>token</returns>
        [HttpPost("debug")]
        public IActionResult PostLogInformation()
        {
            this._logger.Debug("this is message");
            this._logger.Debug("this is message", "this is error code");
            this._logger.Debug("this is message", "this is error code", "this is context");
            this._logger.Debug("this is message", "this is error code", "this is context", "this is key1");
            this._logger.Debug("this is message", "this is error code", "this is context", "this is key1", "this is key2");
            this._logger.Debug("this is message", "this is error code", "this is context", "this is key1", "this is key2", "this is key3");
            return this.Ok();
        }

        /// <summary>
        /// 测试 写入 PostLogCritical 日志
        /// </summary>
        /// <returns>token</returns>
        [HttpPost("warn")]
        public IActionResult PostLogCritical()
        {
            this._logger.Warn("this is message");
            this._logger.Warn("this is message", "this is error code");
            this._logger.Warn("this is message", "this is error code", "this is context");
            this._logger.Warn("this is message", "this is error code", "this is context", "this is key1");
            this._logger.Warn("this is message", "this is error code", "this is context", "this is key1", "this is key2");
            this._logger.Warn("this is message", "this is error code", "this is context", "this is key1", "this is key2", "this is key3");
            return this.Ok();
        }

        /// <summary>
        /// 测试 写入 PostLogDebug 日志
        /// </summary>
        /// <returns>token</returns>
        [HttpPost("error")]
        public IActionResult PostLogError()
        {
            this._logger.Error(new ArgumentNullException("测试记录错误日志"));
            return this.Ok();
        }

        /// <summary>
        /// 测试 写入 PostLogDebug 日志
        /// </summary>
        /// <returns>token</returns>
        [HttpPost("info")]
        public IActionResult PostLogDebug()
        {
            this._logger.Info("this is message");
            this._logger.Info("this is message", "this is error code");
            this._logger.Info("this is message", "this is error code", "this is context");
            this._logger.Info("this is message", "this is error code", "this is context", "this is key1");
            this._logger.Info("this is message", "this is error code", "this is context", "this is key1", "this is key2");
            for (int i = 0; i < 1000; i++)
            {
                this._logger.Info("this is message", "this is error code", "this is context", "this is key1", "this is key2", "this is key3");
            }

            return this.Ok();
        }

        /// <summary>
        /// 测试 写入 PostLogDebug 日志
        /// </summary>
        /// <returns>token</returns>
        [HttpPost("interactive")]
        public IActionResult PostLoginteractive()
        {
            this._logger.Interactive("框架测试", "测试写入Interactive日志", "this is sendAddress", "this is sendData", "this is requestData", "this is keyInfomation", "post");
            return this.Ok();
        }
    }
}